<template>
  <Dialog :funcConfirm="handleClose"
          :funcCancel="handleClose"
          :headerTitle="headerTitle"
          :open="open">
    <template v-slot:body>
      <div class="content-wrapper">
        <div class="scroll-wrapper">
          <div class="record-row" v-for="(item, i) of items" :key="i">
            <div class="cell-point" :style="{background: item.color}"></div>
            <div class="cell-text">{{item.content}}</div>
            <div class="cell-date">{{item.updated_at}}</div>
          </div>
        </div>
      </div>
    </template>
  </Dialog>
</template>

<script>

import operationService from "@api/operationService";
import Dialog from "@/component/dialog/Dialog";

export default {
  components: {Dialog},
  props: {
    uid: String
  },
  data() {
    return {
      headerTitle: '展会记录',
      items: [
      ],
    }
  },
  // 监听属性 类似于data概念
  computed: {
    open() {
      return this.$store.state.dialog.isOpenModuleOperationRecord
    },
  },
  // 监控data中的数据变化
  watch: {
    open(value) {
      if (!value) {
        return
      }
      this.fetchRecord()
    }
  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  },
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {},
  // 方法集合
  methods: {
    handleClose() {
      this.$store.commit('dialog/MODULE_OPERATION_RECORD_OPEN', false)
    },
    fetchRecord() {
      operationService.expoRecord(this.uid).then(res => {
        console.log(res.data.data)
        this.items = res.data.data || []
        this.makeList()
      }).catch((res) => {
        console.log(res)
      })
    },
    makeList() {
      const colors = ['#308AEE', '#24C1F4', '#F4D524', '#F42424']
      for (let i=0; i<this.items.length; i++) {
        this.items[i].color = colors[i%colors.length]
      }
    }
  } // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>
<style scoped lang="scss">
@import "@/style/scss/component/dialog/operationRecordDialog.scss"
</style>
